package com.cjg.array;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;

public class MapDemo {
    public static void main(String[] args) {
        /**
         * 解决方案 : collections
         */
//       Map<String, String> map = new HashMap<>();
       Map<String, String> map = Collections.synchronizedMap(new HashMap<>());
       //有加载因子和初始化容量 this.loadFactor = DEFAULT_LOAD_FACTOR; int initialCapacity)
//        Map<String, String> map = new ConcurrentHashMap<>();
        for (int i = 0; i <20 ; i++) {
            new Thread(()->{
                map.put(Thread.currentThread().getName(),"UUID.randomUUID().toString().substring(0,5)");
                System.out.println(map);
            },String.valueOf(i)).start();
        }
    }
}
